<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/3/29
 * Time: 16:48
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Signconfig extends Base
{
    /**
     * 第一天签到的金币数
     * @return mixed|\think\response\Json
     */
    public function firstSignGold(){
        if(Request::instance()->isPost()){
            $goldNum = input('goldNum');
            $res = Db::table('up_sign_config')->where('id', 1)->setField('score', $goldNum);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $gold = Db::table('up_sign_config')->where('id', 1)->value('score');
        $this->assign('gold', $gold);
        return $this->fetch('signconfig/firstsigngold');
    }
    
    /**
     * 默认邮费
     * @return mixed|\think\response\Json
     */
    public function defaultPostage(){
        if(Request::instance()->isPost()){
            $postgae = input('postage');
            $res = Db::table('up_sign_config')->where('id', 2)->setField('score', $postgae);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $postgae = Db::table('up_sign_config')->where('id', 2)->value('score');
        $this->assign('postage', $postgae);
        return $this->fetch('signconfig/defaultpostage');
    }
    
    /**
     * 闯关失败再次闯关所需的金币数
     * @return mixed|\think\response\Json
     */
    public function needGoldNum(){
        if(Request::instance()->isPost()){
            $goldNum = input('goldNum');
            $res = Db::table('up_sign_config')->where('id', 3)->setField('score', $goldNum);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $gold = Db::table('up_sign_config')->where('id', 3)->value('score');
        $this->assign('gold', $gold);
        return $this->fetch('signconfig/needgoldnum');
    }
    
    /**
     * 闯关经验和金币
     * @return mixed|\think\response\Json
     */
    public function goldAndExp(){
        if(Request::instance()->isPost()){
          
            $data = [
                'score' => input('gold'),
                'exp' => input('exp')
            ];
            $res = Db::table('up_sign_config')->where('id', 4)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $info = Db::table('up_sign_config')->field('score, exp')->where('id', 4)->find();
        $this->assign('info', $info);
        return $this->fetch('signconfig/goldandexp');
    }
    
    /**
     * 完善信息获取的金币数
     * @return mixed|\think\response\Json
     */
    public function perfectionGetGold(){
        if(Request::instance()->isPost()){
            $goldNum = input('goldNum');
            $res = Db::table('up_sign_config')->where('id', 5)->setField('score', $goldNum);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $gold = Db::table('up_sign_config')->where('id', 5)->value('score');
        $this->assign('gold', $gold);
        return $this->fetch('signconfig/perfectiongetgold');
    }
    
    /**
     * 对战所获的经验、金币、题目数量
     * @return mixed|\think\response\Json
     */
    public function awardIndex(){
        if(request()->isAjax ()){
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('sign_config')->where('id', 6)->count();// 获取总条数
            $lists = Db::name('sign_config')
                ->field('id, score, exp, num')
                ->where('id', 6)
                ->page($Nowpage,$limits)
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch('signconfig/awardindex');
    }
    
    /**
     * 编辑对战所获得的经验、金币、题目数量
     * @return mixed|\think\response\Json
     */
    public function awardEdit(){
        if(Request::instance()->isPost()){
            $data = [
                'score' => input('score'),
                'exp' => input('exp'),
                'num' => input('num')
            ];
            $res = Db::table('up_sign_config')->where('id', 6)->update($data);
            if($res){
               return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $info = Db::table('up_sign_config')->where('id', 6)->find();
        $this->assign('info', $info);
        return $this->fetch('signconfig/awardedit');
    }
    
    /**
     * 对战配置---时间&积分  展示
     * @return mixed|\think\response\Json
     */
    public function awardTime(){
        if(request()->isAjax ()){
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('sign_config')->where('id', 6)->count();// 获取总条数
            $lists = Db::name('sign_config')
                ->field('id, times, fen')
                ->where('id', 6)
                ->page($Nowpage,$limits)
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch('signconfig/awardtime');
    }
    
    /**
     * 对战配置---时间&积分  编辑
     * @return mixed|\think\response\Json
     */
    public function awardTimeEdit(){
        if(Request::instance()->isPost()){
            $data = [
                'times' => input('times'),
//                'fen' => input('fen'),
            ];
            $res = Db::table('up_sign_config')->where('id', 6)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $info = Db::table('up_sign_config')->where('id', 6)->find();
        $this->assign('info', $info);
        return $this->fetch('signconfig/awardtimeedit');
    }
    
    /**
     * 超重邮费配置
     * @return mixed|\think\response\Json
     */
    public function overWeight(){
        if(Request::instance()->isPost()){
            $data = [
                'score' => input('score'),
                'exp' => input('exp'),
                'remark' => input('num')
            ];
            $res = Db::table('up_sign_config')->where('id', 8)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $info = Db::table('up_sign_config')
            ->field('score, exp, remark')
            ->where('id', 8)
            ->find();
        $this->assign('info', $info);
        return $this->fetch('signconfig/overweight');
    }
}